#ifndef _AD_CONSTRUCT_H_
#define _AD_CONSTRUCT_H_

#include "grate_constants.h"
#include "words_queue.h"
#include "dfa.h"
#include "input_data.h"

// Main function, called to construct the AD using WORDS_QUEUE, and store AD in the trie DFA
// Returns the maximal number of symbols that were present in the queue at one moment
i64 construct_antidictionary(input_data & INPUT, words_queue * WORDS_QUEUE, dfa * DFA);

// Hadles root stored in cword
void handle_root(const char* cword, int clen, char maxlet, dfa * DFA, input_data & INPUT);

// Recursively builds all the words from cword, adds them to dfa
void build_words(char* cword, int clen, int nlen, int mlen, char letnum, dfa * DFA, input_data & INPUT);

// Returns the miminal length of forbidden word where plen is the length of its root
inline int get_length(int plen, input_data & INPUT);

// Checks if there is a bad suffix in the word in buff, first looks for it in the trie after that calls dumb version
bool has_bad_suffix(const char * buff, int len, int zquant_letters[MAX_WORD_LENGTH][MAX_ALPH_SIZE], dfa * DFA, input_data & INPUT);

// Dumbly checks if a word in buff has a bad suffix
bool has_bad_suffix_dumb(const char * buff, int len, int zquant_letters[MAX_WORD_LENGTH][MAX_ALPH_SIZE], input_data & INPUT);

// ???
bool check_head_tail(const char * buff, int len, int head, int tail, int zquant_letters[MAX_WORD_LENGTH][MAX_ALPH_SIZE], input_data & INPUT);

#endif